<?php

class Default_DemoController extends Zend_Controller_Action {

    protected $_session;

    public function init() {
        $this->_session = new Zend_Session_Namespace('auth');

        if ($this->getRequest()->getActionName() != "login") :
            if ($this->_session->usuario == "") :
                $this->_helper->redirector('login', 'demo');
            endif;
            $this->view->usuario = $this->_session->usuario;
        endif;
    }

    public function indexAction() {
        $this->_helper->redirector('login', 'demo');
    }

    public function loginAction() {

        $form = new Default_Form_Login();
        $form->setAction($this->view->baseUrl() . '/demo/login/');

        if ($this->getRequest()->isPost()) :
            if ($form->isValid($this->_getAllParams())) :
                $this->_session->usuario = $this->getRequest()->getParam("email");
                $this->_helper->redirector("escritorio", "demo");
            endif;
        endif;

        $this->view->usuario = $this->_session->usuario;

        $this->view->form = $form;
    }

    public function logoutAction() {
        $this->_session->unsetAll();
        $this->_helper->redirector('login', 'demo');
    }

    public function escritorioAction() {
        
    }

    public function registrarclienteAction() {

        $form = new Default_Form_Cliente();
        $formTelefonos = new Default_Form_Telefono();
        $formGarantes = new Default_Form_Garante();

        $this->view->form = $form;

        $formTelefonos->setAttrib('class', 'form-inline');

        $this->view->formTelefonos = $formTelefonos;

        $formGarantes->setAttrib('class', 'form-inline');
        $this->view->formGarantes = $formGarantes;
    }

    public function registrarprestamoAction() {


        $this->view->form = $form;
    }

    public function cobrarcuotaAction() {

        ;
    }

    public function buscarclienteAction() {
        $opcion = $this->getRequest()->getParam('opcion');
        if ($opcion == 1) { //crear credito
            $this->view->accion = "registrarprestamo";
            $this->view->nombreBoton = "Registrar Prestamo";
        } else { //cobrar cuota
            $this->view->accion = "cobrarcuota";
            $this->view->nombreBoton = "Cobrar Cuota";
        }
    
    }

}

